public class _04 {

    /*
    来源：力扣（LeetCode）
    链接：https://leetcode.cn/problems/maximum-number-of-removable-characters/
    */
    public static void main(String[] args) {

    }


    class Solution {

        public int maximumRemovals(String s, String p, int[] removable) {
            int l = 0, r = removable.length, m;
            while (l < r) {
                m = (l + r) >> 1;
                if (check(s, p, removable, m)) {
                    l = m + 1;
                } else {
                    r = m;
                }
            }
            return l;
        }

        private boolean check(String s, String p, int[] removable, int m) {
            int a[] = new int[s.length()];
            int len = 0;
            for (int i = 0; i <= m; i++) {
                a[removable[i]] = 1;
            }
            for (int i = 0; i < s.length(); i++) {
                if (a[i] == 0 && s.charAt(i) == p.charAt(len)) {
                    len++;
                }
                if (len == p.length()) {
                    return true;
                }
            }
            return len == p.length();
        }
    }

}

